/**
 * 
 */
package com.buss.core.utils;

import java.io.IOException;

import org.apache.commons.beanutils.BeanUtils;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;


/**
 * 将枚举转换成json
 * @author 高小勇
 * 创建时间:2011-5-11
 * wcms2.0
 */
public class SimpleEnumSerializer extends JsonSerializer<Enum<?>> {


	@Override
	public void serialize(Enum<?> value, JsonGenerator jgen, SerializerProvider provider)
			throws IOException, JsonProcessingException {
			jgen.writeStartObject();
			jgen.writeFieldName("value");
			try {
				String val = BeanUtils.getSimpleProperty(value, "value");
				jgen.writeString(val);
			} catch (Exception e){
				e.printStackTrace();
			}
			
			jgen.writeFieldName("name");
			jgen.writeString(value.name());
			jgen.writeEndObject();
	}}
